package com.zw.utils;

import okhttp3.*;

import java.io.IOException;

public class HttpUtils {
    private static final OkHttpClient client = new OkHttpClient();

    public static String sendPostRequest(String url, String json, String apiKey) throws IOException {
        MediaType JSON = MediaType.get("application/json; charset=utf-8");
        RequestBody body = RequestBody.create(json, JSON);
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .addHeader("Authorization", "Bearer " + apiKey)
                .build();
        try (Response response = client.newCall(request).execute()) {
            return response.body().string();
        }
    }
}
